﻿#region USING STATEMENTS
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Fusion.Management;
using Fusion.Objects;
using Fusion.Content;
#endregion

#region CODE BODY
namespace Fusion.Objects
{
    public class Sprite : BaseObject
    {
        //////////////////////////////////////////////////
        // Data Fields
        //////////////////////////////////////////////////
        private GameTexture Texture;
        private Rectangle source;
        private Color overlay;
        private Vector2 origin;
        private Vector2 scale;
        private SpriteEffects effect;
        private Single rotation;
        private Single depth;

        //////////////////////////////////////////////////
        // Member Properties
        //////////////////////////////////////////////////
        public Color Overlay
        {
            get { return overlay; }
            set { overlay = value; }
        }
        public Rectangle Source
        {
            get { return source; }
            set
            {
                source = value;
                Origin = new Vector2(Source.Width >> 1, source.Height >> 1);
                BoxCollider.ChangeSize(Source.Width, Source.Height);
            }
        }
        public Vector2 Origin
        {
            get { return origin; }
            protected set { origin = value; }
        }
        public Vector2 Scale
        {
            get { return scale; }
            set { scale = value; }
        }
        public SpriteEffects Effect
        {
            get { return effect; }
            set { effect = value; }
        }
        public Single ScaleX
        {
            get { return scale.X; }
            set { scale.X = value; }
        }
        public Single ScaleY
        {
            get { return scale.Y; }
            set { scale.Y = value; }
        }
        public Single Rotation
        {
            get { return rotation; }
            set { rotation = value; }
        }
        public Single Depth
        {
            get { return depth; }
            set { depth = value; }
        }

        //////////////////////////////////////////////////
        // Constructors
        //////////////////////////////////////////////////
        public Sprite(String ResourceFile)
            : base()
        {
            Texture = FTextures.AddTexture(ResourceFile);
            Texture2D FromRes = Texture.Texture;
            BoxCollider = new AABB(Position, FromRes.Width, FromRes.Height, false);
            Source = new Rectangle(0, 0, FromRes.Width, FromRes.Height);
            Origin = new Vector2(FromRes.Width >> 1, FromRes.Height >> 1);
            Overlay = Color.White;
            Scale = new Vector2(1, 1);
            Rotation = 0;
        }

        //////////////////////////////////////////////////
        // Methods
        //////////////////////////////////////////////////

        //////////////////////////////////////////////////
        // BaseObject Methods
        //////////////////////////////////////////////////
        public override void Update(Single Delta)
        {
        }
        public override void Render(Single Delta)
        {
            base.Render(Delta);
            FTextures.Draw(Texture, Position + (Origin * Scale), Source, Overlay, Rotation, Origin, Scale, Effect, Depth);
        }
        public override void CollisionResponse(BaseObject Collider, Single Delta)
        {
        }
        public override void Dispose()
        {
            FTextures.ReleaseTexture(Texture);
        }
    }
}
#endregion

//////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2012 Jeffery Thomas Sventora
//////////////////////////////////////////////////////////////////////////////////////////////